package com.powernode.controller;

import com.github.pagehelper.PageInfo;
import com.powernode.common.Result;
import com.powernode.domain.Bills;
import com.powernode.dto.BillsDto;
import com.powernode.service.BillsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("bills")
public class BillsController {
       @Resource
       private BillsService billsService;

    /**
     * 模糊、分页查询所有账单
     * @param billsDto
     * @return
     */
    @GetMapping("queryBills.do")
       public Result queryBills(BillsDto billsDto){
           PageInfo<Bills> billsPageInfo = billsService.queryBills(billsDto);
           return new Result(0,"查询成功",billsPageInfo.getTotal(),billsPageInfo.getList());
       }

       @PostMapping("addBills.do")
       public Result addBills(Bills bills){
           int i = billsService.insertSelective(bills);
           if(i==1){
               return new Result(200,"添加成功");
           }else {
               return new Result(-1,"添加失败");
           }
       }
}
